package com.hljcj.boot.service;

import com.hljcj.boot.bean.user;
import com.hljcj.boot.dao.UserRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

@Service
@Transactional
public class LoginService {

    @Resource
    private UserRepository userRepository;

    @Transactional
    public String login(String userName, String passWord) {
        user user = new user();
        user.setUserName(userName);
        user.setPassWord(passWord);
        user dbuser = userRepository.findByUserName(user.getUserName());

        if (null != dbuser) {
            if (user.getUserName().equals(dbuser.getUserName())) {
                if (null == user.getPassWord()) {
                    return "请输入密码";
                } else if (user.getPassWord().equals(dbuser.getPassWord())) {
                    return "succ";
                } else {
                    return "密码错误";
                }
            } else {
                return "用户名错误";
            }
        } else {
            return "用户不存在或未输入用户名";
        }

    }
}
